AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )

include('shared.lua')
	
ENT.Name = "Disease"
ENT.Hand = "Blood_Left"
ENT.AnimScale = 3
ENT.Poison = true
ENT.Damage = 55
ENT.DoorDamage = 20
ENT.Pain = Vo.Disease_P
ENT.Death = Vo.Disease_D
ENT.Taunt = Vo.Disease_T
ENT.Attack = {"npc/zombie_poison/pz_throw2.wav",
"npc/zombie_poison/pz_throw3.wav",
"npc/zombie_poison/pz_alert2.wav"}

function ENT:Initialize()

	self:SetModel( "models/zombie/poison.mdl" )
	util.PrecacheSound("npc/zombie/zo_attack2.wav")
	
	self:SetHullType( HULL_HUMAN );
	self:SetHullSizeNormal();
	
	self:SetSolid( SOLID_BBOX ) 
	self:SetMoveType( MOVETYPE_STEP )
	
	self:CapabilitiesAdd( CAP_MOVE_GROUND | CAP_ANIMATEDFACE | CAP_TURN_HEAD | CAP_AIM_GUN )
	
	self:SetMaxYawSpeed( 5000 )
	
	//don't touch stuff above here
	self:SetHealth(math.random(60,70))
	self.MaxHealth = 90

end

function ENT:SelectSchedule()

	local schdChase = ai_schedule.New( "AIFighter Chase" ) //creates the schedule used for this npc
	
	schdChase:AddTask( "FindEnemy", 		{ Class = "player", Radius = 200000 } )
	schdChase:EngTask( "TASK_GET_PATH_TO_ENEMY", 0 )
    schdChase:EngTask( "TASK_RUN_PATH_TIMED", 0.2 )
    schdChase:EngTask( "TASK_WAIT", 0.2 ) 
	
	local close = false
	local tbl = team.GetPlayers(TEAM_HUMANS)
	table.Add(tbl,ents.FindByClass("prop_door_rotating"))
	table.Add(tbl,ents.FindByModel("models/props_debris/wood_chunk03a.mdl"))
	table.Add(tbl,ents.FindByModel("models/props_debris/wood_chunk03b.mdl"))
	for k,v in pairs(tbl) do
		if v:GetPos():Distance(self:GetPos()) < 100 then
			close = true
		end
	end
	
	if close then
		schdChase:EngTask( "TASK_STOP_MOVING", 			0 )
		schdChase:EngTask( "TASK_FACE_ENEMY", 			0 )
		schdChase:AddTask( "PlaySequence", 				{ Name = "melee_01", Speed = .9 } )
	end

	self:StartSchedule( schdChase ) 

end

function ENT:OnTakeDamage(dmg)
	if not dmg:GetAttacker():IsPlayer() and not dmg:GetAttacker():GetOwner():IsPlayer() then
		dmg:SetDamage(0)
	end
	self:SetHealth(math.Clamp(self:Health() - dmg:GetDamage(),0,100))
	if self:Health() <= 0 then
		if self:IsValid() then
			self:DoDeath(dmg)
			
			local gas = ents.Create( "sent_poisongas" )
			gas:SetPos( self:GetPos() )
			gas:SetOwner( self )
			gas:Spawn()
			gas:Activate()
			
		end
	else
		//self:AddAttackerDamage(dmg:GetAttacker(),dmg:GetDamage(),true)
		if math.random(1,3) == 1 then
			self:VoiceSound(ChooseRandom(self.Pain),100)
		end
	end
end 